﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpaceGame
{
    public abstract class SpaceShip : MovingObject, IAnimatable, ICollidable
    {
        protected bool isShooting = false;

        private List<char[,]> animationFrameList;
        private int animationFrameIndex;
            
        public SpaceShip(Position topLeft, char[,] image, int speed, Position direction)
            : base(topLeft, image, speed, direction)
        {
            animationFrameList = new List<char[,]>();
            animationFrameList.Add(this.image);
            animationFrameIndex = 0;
        }

        public void Shoot()
        {
            this.isShooting = true;
        }

        public override void Update()
        {
            base.Update();

            //this.UpdatePosition();
            this.image = this.NextFrame;
        }

        public char[,] NextFrame
        {
            get
            {
                if (this.animationFrameIndex == this.animationFrameList.Count)
                {
                    this.animationFrameIndex = 0;
                }
                return this.animationFrameList[animationFrameIndex++];
            }
        }

        public List<char[,]> AnimationList
        {
            get
            {
                return new List<char[,]>(this.animationFrameList);
            }
        }

        public void AddFrame(char[,] newFrame)
        {
            this.animationFrameList.Add(newFrame);
        }

        public virtual void CollisionResponse(ICollidable instance)
        {
            this.IsDestroyed = true;
        }
    }
}
